package pl.drypisy;

import android.database.Cursor;
import android.util.Log;

import com.google.android.maps.GeoPoint;

/**
 * Class containing checkpoint informations, and implements operation with checkpoint
 * @author Marcin Pilat
 * @version 1.0
 */
public class Checkpoint {
	/**
	 * @param _chid
	 * @param _rid
	 * @param lat latitude in double
	 * @param lon longitude in double
	 * @param _name checkpoint name
	 * @param _task question for this checkpoint
	 * @param _hint1
	 * @param _hint2
	 * @param _hint3
	 * @param _hint4
	 * @param _answer
	 */
	public Checkpoint(int _chid, int _rid, double lat, double lon, String _name, String _task, String _hint1, String _hint2, String _hint3, String _hint4, String _answer){
		p = new GeoPoint((int)(lat*1E6), (int)(lon*1E6));
		rid = _rid;
		chid = _chid;
		name = _name;
		task = _task;
		hint = new String []{_hint1,_hint2,_hint3,_hint4};
		answer = _answer;
		points = 0;
	}
	
	private GeoPoint p;
	private String name;
	private String task;
	private String [] hint;
	private String answer;
	private int chid;
	private int rid;
	private int points;
	
	
	public int getChId(){
		return chid;
	}
	
	public int getRId(){
		return rid;
	}
	
	public GeoPoint getGeoPoint(){
		return p;
	}
	
	public double getLatitude(){
		return p.getLatitudeE6()/1E6;
	}
	
	public double getLongitude(){
		return p.getLongitudeE6()/1E6;
	}
	
	public String getName(){
		return name;
	}
	
	public String getTask(){
		return task;
	}
	
	public String[] getHints(){
		return hint;
	}
	
	public String getAnswer(){
		return answer;
	}
	
	public void setPoints(int p){
		points = p;
	}
	
	public int getPoints(){
		return points;
	}
	
	/**
	 * Getting Checkpoint from cursor
	 * @param c Cursor
	 * @return Checkpoint
	 */
	static public Checkpoint getCheckpointFromCursor(Cursor c){
		Checkpoint ch = new Checkpoint(c.getInt(0), c.getInt(1), Double.parseDouble(c.getString(3)), Double.parseDouble(c.getString(4)),c.getString(2), c.getString(5), c.getString(7), c.getString(8), c.getString(9), c.getString(10),  c.getString(6));
		return ch;
	}
	
	@Override
	public String toString(){
		return "Name: " + name + " Task: " + task + " Answer: " +  answer + " hints: " + hint[0] + " " + hint[1] + " " + hint[2] + " " + hint[3];
	}
}
